﻿// Auxilary class to package a comparison delegate as an object with a comparer interface.
//
// Copyright (C) 2012 M. de Wolde
//
// This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
//
// 2012-07-10 MIWO Created.

using System;
using System.Collections.Generic;

namespace Lemody.Glu {

/// <summary>Auxilary class to package a comparison delegate as an object with a comparer interface.</summary>
/// <remarks><![CDATA[
///     This class is used to package a supplied Comparison<T> in order to access support that expects an IComparer<T>.
/// ]]></remarks>
internal class VectorComparisonComparer<T>: IComparer<T>
{
    /// <summary>Comparison delegate.</summary>
    private readonly Comparison<T> _comparison;

    /// <summary>Constrcutor.</summary>
    /// <param name="comparison">I: Comparison delegate.</param>
    internal VectorComparisonComparer(Comparison<T> comparison)
    {
        _comparison = comparison;
    }

    /// <summary>Compares the elements, using the stored delegate.</summary>
    /// <param name="x">I: First element in the compare.</param>
    /// <param name="y">I: Second element in the compare.</param>
    public int Compare(T x, T y)
    {
        return _comparison(x, y);
    }
}

} // namespace
